import Vue from 'vue'
import VueRouter from 'vue-router'
import home from "./home"
import user from "./user"
import loginsRouter from './routers'

Vue.use(VueRouter)

const routes = [
  ...home,
  ...user,
  ...loginsRouter,
  {
    path:"*",
    component:()=>import("../views/Notfound.vue")
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  // console.log(to.path);
  if(to.path == '/home'){
    if(sessionStorage.getItem('token') != null){
      next()
    }else(
      next('/userlogin/login')
    )
  }else{
      next()
  }

})

export default router
